package com.silence.Interface_test;

import java.util.ArrayList;

public class StudentOperatorImpl2 implements StudentOperator {

    @Override
    public void printAllInfo(ArrayList<Student> students) {
        int nan = 0;
        int nv = 0;
        System.out.println("----------全班全部信息2----------");
        for (Student student : students) {
            System.out.println(student);
            if (student.getSex() == '男') {
                nan++;
            }
            else {
                nv++;
            }
        }
        System.out.println("男生人数:"+nan+", 女生人数:"+nv);
        System.out.println("总人数："+students.size());
        System.out.println("------------------------------");
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double sum = 0;
        double max = students.get(0).getScore();
        double min = students.get(0).getScore();
        for (Student student : students) {
            sum += student.getScore();
            if(student.getScore() >max){
                max = student.getScore();
            }
            if(student.getScore() <min){
                min = student.getScore();
            }
        }
        sum = sum-min-max;
        System.out.println("-----------全班平均分2-----------");
        System.out.println("学生的最高分:"+max);
        System.out.println("学生的最低分:"+min);
        System.out.println("平均分:" +  sum/ (students.size()-2));
        System.out.println("------------------------------");

    }
}
